<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1000" destroy-on-close @closed="$emit('closed')" :align-center="true" :close-on-click-modal="false">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="110px" label-position="right">
			<div class="sketch_content">
                <el-form-item label="发货数量" prop="size_data">
                    <sc-form-table ref="table" v-model="form.size_data" :addTemplate="addTemplate" placeholder="暂无数据" hideAdd :show-summary="true">
                        <el-table-column prop="size" label="尺码" width="130"></el-table-column>
                        <el-table-column prop="order_num" label="下单数量" width="130"></el-table-column>
                        <el-table-column prop="return_num" label="退货数量" width="130"></el-table-column>
                        <el-table-column prop="num" label="发货数量" min-width="180">
                            <template #default="scope">
                                <el-input v-model="scope.row.num" placeholder="请输入数量"></el-input>
                            </template>
                        </el-table-column>
                    </sc-form-table>
                </el-form-item>
			</div>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确定</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '添加客户',
					edit: '编辑客户',
					over: '原单发货'
				},
				visible: false,
				isSaveing: false,
                grade:"潜力",
				//表单数据
				form: {
					order_no:"",
                    size_data:[]
				},
				//验证规则
				rules: {
                    comment: [
						{required: true, message: '请输入工厂报价'}
					],
				},
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res  = [];
						res = await this.$API.order.getOrder.originalShipment.post(this.form);
						if(res.code == 1){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						    this.isSaveing = false;
						}
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			setData(data){
                console.log('data :>> ', data);
                this.form.order_no = data.order_no
                let a = []
                data.orderDetail.map(item=>{
                    a.push({
                        id:item.id,
                        size:item.goods_size,
                        order_num:item.num,
                        return_num:item.return_num,
                        num:item.return_num
                    })
                })
                this.form.size_data = a
			},
		}
	}
</script>

<style lang="scss">
.el-form-item--default{
    align-items: center;
}
</style>
